package com.dingding.web.recruit.action;

import java.util.List;

import javax.annotation.Resource;

import com.dingding.common.core.util.DateFormatUtil;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.facde.recruit.IDriverRecruitFacade;
import com.dingding.facde.recruit.dto.DriverRecruitCityDTO;
import com.dingding.facde.recruit.dto.ReqGetDriverRecruitInfoDTO;
import com.dingding.facde.recruit.dto.ReqSignUpDTO;
import com.dingding.facde.recruit.dto.ReqValidateCode;
import com.dingding.facde.recruit.dto.ResGetDriverRecruitInfoDTO;
import com.dingding.facde.recruit.dto.ResValidateCode;
import com.dingding.web.base.action.BaseAction;

/**
 * 
 * @ClassName: DriverRecruitAction 
 * @Description: 司机招募Action
 * @author YHQ
 * @date 2016年11月11日 下午3:07:08
 * @since V2.5.6
 * 
 */
@SuppressWarnings("serial")
public class DriverRecruitAction extends BaseAction{

	@Resource(name = "driverRecruitFacade")
	private IDriverRecruitFacade driverRecruitFacade;
	
	// 获取招募司机报名信息请求Bean
	private ReqGetDriverRecruitInfoDTO recruitInfo = new ReqGetDriverRecruitInfoDTO();
	// 招募司机报名信息请求Bean
	private ReqSignUpDTO reqSignUpDTO = new ReqSignUpDTO();
	// 验证手机验证码
	private ReqValidateCode reqValidateCode = new ReqValidateCode();
	
	private String carType;			// 准驾车型	
	private String driLicDate;		// 初领驾驶证日期
	private String idCard;			// 身份证
	private String licDataNo;		// 驾驶证档案编号
	private String name;			// 姓名
	private String cityId;			// 期望城市编号
	private String telPhone;		// 手机号
	private String code;			// 验证码
	private Integer recId;			// 主键Id
	
	/**
	 * @Title: getDriverRecruitCity
	 * @Description: 获取招募城市
	 * @author yuHaiQing
	 * @return String 返回类型
	 */
	public String getDriverRecruitCity() {

		// 获取全部的招募城市列表
		List<DriverRecruitCityDTO> recruitCityDTOs = driverRecruitFacade.getDriverRecruitCity();

		// 把返回信息封装为json
		String jsonp = super.getResJsonp(recruitCityDTOs);
		super.write(jsonp);

		return null;
	}
	
	/**
	 * 
	 * @Title: getDriverRecruitInfo 
	 * @Description: 获取司机招募报名信息
	 * @author YHQ 
	 * @return String    返回类型
	 * 
	 */
	public String getDriverRecruitInfo(){
		
		// 获取司机招募报名信息
		ResGetDriverRecruitInfoDTO recruitInfoDTO = driverRecruitFacade.getDriverRecruitInfo(driverRecruitInfo());
		
		// 把返回信息封装为json
		String jsonp = super.getResJsonp(recruitInfoDTO,"yyyy-MM-dd");
		super.write(jsonp);

		return null;
	}

	/**
	 * 
	 * @Title: driverSignUp 
	 * @Description: 司机报名(司机招募)
	 * @author YHQ 
	 * @since V2.5.6
	 * @return String    返回类型
	 * 
	 */
	public String driverSignUp(){
		
		// 司机报名
		boolean flag = driverRecruitFacade.driverSignUp(geSignUpDTO());
		if(flag){
			super.write(super.getResJsonp("success"));
		}else{
			super.write(super.getResJsonp("error"));
		}
		
		return null;
	}
	
	
	/**
	 * 
	 * @Title: validateCode 
	 * @Description: 验证手机验证码
	 * @author YHQ 
	 * @since V2.5.6
	 * @return String    返回类型
	 * 
	 */
	public String validateCode(){
		
		// 验证手机验证码
		ResValidateCode resValidateCode = driverRecruitFacade.validateCode(getValidateCode());
		
		// 把返回信息封装为json
		String jsonp = super.getResJsonp(resValidateCode);
		super.write(jsonp);
		
		return null;
	}
	
	/**
	 * 
	 * @Title: graphicVerification 
	 * @Description: 图形验证
	 * @author YHQ 
	 * @since V2.5.6
	 * @return String    返回类型
	 * 
	 */
	public String graphicVerification(){
		
		// 获取session值
		String str = (String) request.getSession().getAttribute(request.getSession().getId());
		
		// 验证客户端传入参数与session中的值是否相同
		if(ToolUtil.isNotBlank(str) && str.toUpperCase().equals(code.toUpperCase())){
			super.write(super.getResJsonp("success"));
		}else{
			super.write(super.getResJsonp("error"));
		}
		
		return null;
	}
	
	/**
	 * 
	 * @Title: geSignUpDTO 
	 * @Description: 客户端传入参数封装成Bean
	 * @author YHQ 
	 * @since V2.5.6
	 * @return ReqSignUpDTO    返回类型
	 * 
	 */
	public ReqSignUpDTO geSignUpDTO(){
		
		reqSignUpDTO.setCarType(carType);
		if(ToolUtil.isNotBlank(driLicDate)){
			reqSignUpDTO.setDriLicDate(DateFormatUtil.parseYyMmDd(driLicDate));
		}
		reqSignUpDTO.setIdCard(idCard);
		reqSignUpDTO.setLicDataNo(licDataNo);
		reqSignUpDTO.setName(name);
		reqSignUpDTO.setCityId(cityId);
		reqSignUpDTO.setTelPhone(telPhone);
		reqSignUpDTO.setRecId(recId);
		reqSignUpDTO.setDriverYear(DateFormatUtil.getDriving(driLicDate));
		
		return reqSignUpDTO;
	}
	
	/**
	 * 
	 * @Title: driverRecruitInfo 
	 * @Description: 客户端传入参数封装成Bean
	 * @author YHQ 
	 * @since V2.5.6
	 * @return ReqSignUpDTO    返回类型
	 * 
	 */
	public ReqGetDriverRecruitInfoDTO driverRecruitInfo(){
		
		recruitInfo.setTelPhone(telPhone);
		
		return recruitInfo;
	}
	
	/**
	 * 
	 * @Title: driverRecruitInfo 
	 * @Description: 客户端传入参数封装成Bean
	 * @author YHQ 
	 * @since V2.5.6
	 * @return ReqSignUpDTO    返回类型
	 * 
	 */
	public ReqValidateCode getValidateCode(){
		
		reqValidateCode.setTelPhone(telPhone);
		reqValidateCode.setCode(code);
		
		return reqValidateCode;
	}
	
	public IDriverRecruitFacade getDriverRecruitFacade() {
		return driverRecruitFacade;
	}

	public void setDriverRecruitFacade(IDriverRecruitFacade driverRecruitFacade) {
		this.driverRecruitFacade = driverRecruitFacade;
	}

	public String getCarType() {
		return carType;
	}

	public void setCarType(String carType) {
		this.carType = carType;
	}

	public String getDriLicDate() {
		return driLicDate;
	}

	public void setDriLicDate(String driLicDate) {
		this.driLicDate = driLicDate;
	}

	public String getIdCard() {
		return idCard;
	}

	public void setIdCard(String idCard) {
		this.idCard = idCard;
	}

	public String getLicDataNo() {
		return licDataNo;
	}

	public void setLicDataNo(String licDataNo) {
		this.licDataNo = licDataNo;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCityId() {
		return cityId;
	}

	public void setCityId(String cityId) {
		this.cityId = cityId;
	}

	public String getTelPhone() {
		return telPhone;
	}

	public void setTelPhone(String telPhone) {
		this.telPhone = telPhone;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Integer getRecId() {
		return recId;
	}

	public void setRecId(Integer recId) {
		this.recId = recId;
	}
	
}
